package com.quanyan.stadiumScheduler.biz.redis.impl;

import com.quanyan.redisCluster.utils.RedisConstants;
import com.quanyan.redisCluster.utils.RedisKey;
import com.quanyan.stadiumScheduler.biz.redis.DefaultConfigCacheDao;
import com.quanyan.stadiumScheduler.cache.MyRedisTemplate;
import com.quanyan.stadiumScheduler.cache.StadiumRedisConstants;
import com.quanyan.stadiumScheduler.entity.TbGameCommonParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author xiaoxiao
 * @date 16/4/11-14:42
 *
 * 缓存基础类
 */

@Service
public class DefaultConfigCacheDaoImpl implements DefaultConfigCacheDao {

    @Autowired
    MyRedisTemplate myRedisTemplate;

    //超时时间
    private final static int EXPIRE_TIME = 60*10;

    @Override
    public List<TbGameCommonParameter> getTbGameCommonParameterListMsgFromCache(String groupKey) {
        String key = StadiumRedisConstants.getUserCategoryAndCityScoreRankNum(groupKey);
        RedisKey redisKey = new RedisKey(RedisConstants.STADIUM_FAMILY_KEY, key);
        return (List<TbGameCommonParameter>) myRedisTemplate.get(redisKey);
    }

    @Override
    public void initTbGameCommonParameterMsgToCache(String groupKey, List<TbGameCommonParameter> list) {
        String key = StadiumRedisConstants.getUserCategoryAndCityScoreRankNum(groupKey);
        RedisKey redisKey = new RedisKey(RedisConstants.STADIUM_FAMILY_KEY, key);
        myRedisTemplate.setWithExpireTime(redisKey, list, EXPIRE_TIME);
    }

}
